﻿using DARE.Tools;
using Microsoft.Xna.Framework;

namespace DARE
{
    public class CStartAnimBlender : IBlendController
    {
        #region Flieds

        private double m_elapsed;
        private double m_duration;
        private CAnimConfig m_conf;
        private float m_startBlend;

        #endregion

        #region Properties

        public int Priority { get; set; }

        #endregion

        #region Event

        public event BlendEvent BlendingEnded;

        #endregion

        #region CTOR

        public CStartAnimBlender(double duration, CAnimConfig _conf)
        {
            m_duration = duration;
            m_elapsed = 0;
            m_conf = _conf;
            m_startBlend = _conf.BlendFactor;
        }

        #endregion

        #region Method

        public void Update(GameTime time)
        {
            if (m_elapsed > m_duration)
                return;
            m_elapsed += time.ElapsedGameTime.TotalMilliseconds;
            m_conf.BlendFactor = (float)(m_elapsed / m_duration);
            if (m_elapsed > m_duration)
                BlendingEnded.InvokeTest(this);
        }

        #endregion
    }
}
